package jrain.fw.core.log;

import jrain.fw.core.business.BusinessRequest;

/**
 * <pre>
 * 作者：3244924214@qq.com 
 * 描述： 日志默认实现
 * </pre>
 */
public class NoLoggingImpl extends BaseLogger implements Logger {

	private static final String TRACE = "trace";
	private static final String DEBUG = "debug";
	private static final String INFO = "info";
	private static final String WRAN = "wran";
	private static final String ERROR = "error";

	private String loggerName;
	private boolean traceEnable = true;
	private boolean debugEnable = true;
	private boolean infoEnable = true;
	private boolean warnEnable = true;
	private boolean errorEnable = true;

	public NoLoggingImpl(String loggerName) {
		this.loggerName = loggerName;
	}

	public String getLoggerName() {
		return this.loggerName;
	}

	public boolean isTraceEnabled() {
		return traceEnable;
	}

	public boolean isDebugEnabled() {
		return debugEnable;
	}

	public boolean isInfoEnabled() {
		return infoEnable;
	}

	public boolean isWarnEnabled() {
		return warnEnable;
	}

	public boolean isErrorEnabled() {
		return errorEnable;
	}

	// trace-----------------------------------------------------
	public void trace(String msg) {
		out(TRACE, msg);
	}

	public void trace(String format, Object... argArray) {
		out(TRACE, format, argArray);
	}

	public void trace(BusinessRequest request, String msg) {
		out(TRACE, request, msg);
	}

	public void trace(BusinessRequest request, String format, Object... argArray) {
		out(TRACE, request, format, argArray);
	}

	// debug-----------------------------------------------------

	public void debug(String msg) {
		out(DEBUG, msg);
	}

	public void debug(String format, Object... argArray) {
		out(DEBUG, format, argArray);
	}

	public void debug(String msg, Throwable t) {
		out(DEBUG, msg, t);
	}

	public void debug(String format, Throwable t, Object... argArray) {
		out(DEBUG, format, t, argArray);
	}

	// -----
	public void debug(BusinessRequest request, String msg) {
		out(DEBUG, request, msg);
	}

	public void debug(BusinessRequest request, String msg, Throwable t) {
		out(DEBUG, request, msg, t);

	}

	public void debug(BusinessRequest request, String format, Object... argArray) {
		out(DEBUG, request, format, argArray);
	}

	public void debug(BusinessRequest request, String format, Throwable t, Object... argArray) {
		out(DEBUG, request, format, t, argArray);
	}

	// info-----------------------------------------------------

	public void info(String msg) {
		out(INFO, msg);
	}

	public void info(String format, Object... argArray) {
		out(INFO, format, argArray);
	}

	public void info(String msg, Throwable t) {
		out(INFO, msg, t);
	}

	public void info(String format, Throwable t, Object... argArray) {
		out(INFO, format, t, argArray);
	}

	// -----
	public void info(BusinessRequest request, String msg) {
		out(INFO, request, msg);
	}

	public void info(BusinessRequest request, String msg, Throwable t) {
		out(INFO, request, msg, t);

	}

	public void info(BusinessRequest request, String format, Object... argArray) {
		out(INFO, request, format, argArray);
	}

	public void info(BusinessRequest request, String format, Throwable t, Object... argArray) {
		out(INFO, request, format, t, argArray);
	}
	// warn-----------------------------------------------------

	public void warn(String msg) {
		out(WRAN, msg);
	}

	public void warn(String format, Object... argArray) {
		out(WRAN, format, argArray);
	}

	public void warn(String msg, Throwable t) {
		out(WRAN, msg, t);
	}

	public void warn(String format, Throwable t, Object... argArray) {
		out(WRAN, format, t, argArray);
	}

	// -----
	public void warn(BusinessRequest request, String msg) {
		out(WRAN, request, msg);
	}

	public void warn(BusinessRequest request, String msg, Throwable t) {
		out(WRAN, request, msg, t);

	}

	public void warn(BusinessRequest request, String format, Object... argArray) {
		out(WRAN, request, format, argArray);
	}

	public void warn(BusinessRequest request, String format, Throwable t, Object... argArray) {
		out(WRAN, request, format, t, argArray);
	}
	// error-----------------------------------------------------

	public void error(String msg) {
		out(ERROR, msg);
	}

	public void error(String format, Object... argArray) {
		out(ERROR, format, argArray);
	}

	public void error(String msg, Throwable t) {
		out(ERROR, msg, t);
	}

	public void error(String format, Throwable t, Object... argArray) {
		out(ERROR, format, t, argArray);
	}

	// -----
	public void error(BusinessRequest request, String msg) {
		out(ERROR, request, msg);
	}

	public void error(BusinessRequest request, String msg, Throwable t) {
		out(ERROR, request, msg, t);

	}

	public void error(BusinessRequest request, String format, Object... argArray) {
		out(ERROR, request, format, argArray);
	}

	public void error(BusinessRequest request, String format, Throwable t, Object... argArray) {
		out(ERROR, request, format, t, argArray);
	}

	// out-----------------------------------------------------
	private void out(String type, String msg) {
		if (msg != null) {
			String nmsg = loggerName + " : " + type + ":" + msg;
			if (ERROR.equals(type)) {
				System.err.println(nmsg);
			} else {
				System.out.println(nmsg);
			}
		}
	}

	private void out(String type, String format, Object... argArray) {
		if (format != null) {
			String msg = formart(format, argArray);
			String nmsg = loggerName + " : " + type + ":" + msg;
			if (ERROR.equals(type)) {
				System.err.println(nmsg);
			} else {
				System.out.println(nmsg);
			}
		}
	}

	private void out(String type, String msg, Throwable t) {
		out(type, msg);
		if (t != null) {
			t.printStackTrace();
		}
	}

	private void out(String type, String format, Throwable t, Object... argArray) {
		out(type, format, argArray);
		if (t != null) {
			t.printStackTrace();
		}
	}

	// ----------------------------------------------
	private void out(String type, BusinessRequest request, String msg) {
		if (msg != null) {
			String tmsg = getTraceMsg(request, msg);
			String nmsg = loggerName + " : " + type + ":" + tmsg;
			if (ERROR.equals(type)) {
				System.err.println(nmsg);
			} else {
				System.out.println(nmsg);
			}
		}
	}

	private void out(String type, BusinessRequest request, String format, Object... argArray) {
		if (format != null) {
			String fmsg = formart(format, argArray);
			String tmsg = getTraceMsg(request, fmsg);
			String nmsg = loggerName + " : " + type + ":" + tmsg;
			if (ERROR.equals(type)) {
				System.err.println(nmsg);
			} else {
				System.out.println(nmsg);
			}
		}
	}

	private void out(String type, BusinessRequest request, String msg, Throwable t) {
		out(type, request, msg);
		if (t != null) {
			t.printStackTrace();
		}
	}

	private void out(String type, BusinessRequest request, String format, Throwable t, Object... argArray) {
		out(type, request, format, argArray);
		if (t != null) {
			t.printStackTrace();
		}
	}

}
